# 字符串定义： 定义在一对引号的数据
from pydoc import stripid
from random import choice

data_01 = ""
data_02 = "192.168.10.1"

print(type(data_01), type(data_02))

# 原始 raw 字符串, 避免特殊字符转义 \n  \t
win_file_name = r"D:\nerwir\test\logo.jpg"
print(win_file_name)

#------字符串操作符------
# 1、字符串拼接 +
print("Ab" + "CD")

# 2、字符串重复  *
print("--------" * 3)

# 3、获取字符串长度 len()
print(len("hello world"))

# 4、判断字符串包含关系 in, not in
print("el" in "hello")
print("el" not in "hello")

# 5、字符串索引   字符串[下标]，从左：0开始 从右：-1 开始
data_01 = "Linux"
print(data_01[0])
print(data_01[-2])

# 6、获取字符串切片    字符串[起始下标:终止下标:步长]   字符串[开始:结束:步长]   默认步长为1
data_01 = "Linux"
print(data_01[0:3])
print(data_01[3:])
print(data_01[:3])
# 起始下标和终止下标可以省略，默认输出源字符串
print(data_01[::])
# 7、字符串倒置
print(data_01[::-1])

# ------------字符串对象的操作方法-----------
# 1、转换大小写 upper() lower()
print("aBcD".upper())
print("aBcD".lower())
print("aBcD".capitalize())

# 2、判断字符串的开头、结尾
print("Linux".startswith("Lin"))
print("Linux".endswith("x"))

# 3、删除字符串左、右两侧的空白
data_01 = "  Linux  "
print(data_01.strip())
print(data_01.lstrip())
print(data_01.rstrip())

# 4、分割字符串 split() 默认空白分割
data_01 = "nginx    java    tomcat  redis"
new_data_01 = data_01.split()
print(new_data_01)
print(new_data_01[-2])

ip = "192.168.32.52"
new_ip = ip.split(".")
print(new_ip)
print(new_ip[-3])
print(type((new_ip)[-3]))

# 5、判断字符串的组成结构
print("123456".isdigit())
print("abcdef".isalpha())

# 6、字符串替换 replace()
file_name = "/etc/sysconfig/network-scripts/ifcfg-eth0"
new_file_name = file_name.replace("eth0", "ens33")
print(new_file_name)

print("----------------------------------------------------------------------------------------------------------------")
choice = input("执行/取消[Y/N]? ").upper().strip()
if choice.upper() == "Y":
    print("执行操作")
else:
    print("取消操作")